package com.lx.sync.config.controller;

import com.lx.sync.config.model.SyncConfig;
import com.lx.sync.config.service.SyncConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 同步配置控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/sync/config")
public class SyncConfigController {

    @Autowired
    private SyncConfigService syncConfigService;

    /**
     * 保存同步配置
     */
    @PostMapping
    public boolean saveSyncConfig(@RequestBody SyncConfig config) {
        return syncConfigService.saveSyncConfig(config);
    }

    /**
     * 更新同步配置
     */
    @PutMapping
    public boolean updateSyncConfig(@RequestBody SyncConfig config) {
        return syncConfigService.updateSyncConfig(config);
    }

    /**
     * 获取同步配置
     */
    @GetMapping("/{idxName}")
    public SyncConfig getSyncConfig(@PathVariable String idxName) {
        return syncConfigService.getSyncConfig(idxName);
    }

    /**
     * 获取所有同步配置
     */
    @GetMapping("/list")
    public List<SyncConfig> getAllSyncConfigs() {
        return syncConfigService.getAllSyncConfigs();
    }

    /**
     * 删除同步配置
     */
    @DeleteMapping("/{idxName}")
    public boolean deleteSyncConfig(@PathVariable String idxName) {
        return syncConfigService.deleteSyncConfig(idxName);
    }

    /**
     * 启用/禁用同步配置
     */
    @PutMapping("/{idxName}/toggle")
    public boolean toggleSyncConfig(@PathVariable String idxName, @RequestParam boolean enabled) {
        return syncConfigService.toggleSyncConfig(idxName, enabled);
    }
} 